# @Time    :2025/8/7 上午11:37
# @Author  :XiaoJiang
# @File    :反射.py
# @Software: PyCharm、

"""
    01:操作类属性和类方法、静态方法
        获取属性：getattr(类名,"属性名称字符串")
        设置属性：setattr(类名,"属性名称字符串",需要设置的新值)

        获取方法：getattr(类名,"方法名称字符串")
        执行方法：getattr(类名,"方法名称字符串")()

    02：操作对象属性和对象方法
        获取属性：getattr(类名,"属性名称字符串")
        执行方法：getattr(类名,”方法名称字符串")(参数)

    03：操作第三方模块
        执行方法：getattr(模块名称，”方法名称字符串“)(参数)

    04：自己的模块
        执行方法：getattr(sys.modules['__main__']，”方法名称字符串“)(参数)

"""

def add():
    print("加法运算")


import sys
mymodel = sys.modules['__main__']
mymodel.add()

getattr(mymodel,"add")()




# import time
# # time.sleep(3)
# getattr(time, "sleep")(3)
# print("hello world")










# class Person:
#
#     person_num1 = "1"
#     person_num2 = "2"
#     person_num3 = "3"
#     person_num4 = "4"
#
#     @classmethod
#     def help(cls):
#         print("帮助动作")
#     @classmethod
#     def login(cls):
#         print("登录动作")
#     @classmethod
#     def register(cls):
#         print("注册动作")
#
#     def __init__(self,username):
#         self.username = username
#
#     def study(self,name):
#         print(self.username + "正在学习%s..."%project)
#
# lufei = Person("路飞")
#
# getattr(lufei,"study")("反射技术")


# 传统做法
# num = input("请输入您要查询的编号：")
# if num == "person_num1":
#     print(Person.person_num1)
# if num == "person_num2":
#     print(Person.person_num2)
# if num == "person_num3":
#     print(Person.person_num3)


# 传统做法
# print(Person.person_num1)
# Person.help()

# 反射做法

# num = input("请输入您要查询的编号：")
# print(getattr(Person,num))

# method = input("请输入您要执行的方法名称:")
# getattr(Person,method)()